package day20.zhiyou100;

import java.util.concurrent.*;

public class ExecutorsPool2 {

    // 使用的接口Callable
    public static void m1() throws Exception {
        // 通过工厂执行器 Executors
        // 创建线程池对象
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        // 执行任务
        //Thread thread = new Thread(run)
        Future<Integer> future = threadPool.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int a = 10;
                int b = 20;
                return a+b;
            }
        });
        // 获取任务执行的结果值
        Integer o = future.get();
        System.out.println(o);
        // 关闭线程池
        threadPool.shutdown();
    }

    public static void main(String[] args) throws Exception {
        m1();
    }
}
